require 'vacuum'

request = Vacuum.new
# Only Root certificate is allowd for advertising API
request.configure(
    aws_access_key_id: 'ANKIAJ6OSU4BHONWNLLPQ',
    aws_secret_access_key: '7N3yZ8jkiHAm96l0k33X/2b0BI3Urd8KRxzobJMSP',
    associate_tag: 'l0cbc-20'
)

response = request.item_lookup(
  query: {
    'ItemId' => '635753490879',
    'IdType' => 'UPC',
    'SearchIndex' => 'All',
    'ResponseGroup' => 'Large'
  }
)

class Item
  def self.search_by_upc(upc)
    response = request.item_lookup(
      query: {
        'ItemId' => '635753490879',
        'IdType' => 'UPC',
        'SearchIndex' => 'All',
        'ResponseGroup' => 'Large'
      }
    )
    attrs_h = response.to_h
    attrs = attrs_h["ItemLookupResponse"]['Items']['Item']['ItemAttributes']

    self.rank = attrs_h["ItemLookupResponse"]['Items']['Item']['SalesRank']
    self.asin = attrs_h["ItemLookupResponse"]['Items']['Item'][ASIN']
    self.title = attrs['Title']
    self.price = attrs['ListPrice']['FormattedPrice']
    self.tiny_image = attrs_h["ItemLookupResponse"]['Items']['Item']['ImageSets']['ImageSet']['TinyImage']
    self.medium_image = attrs_h["ItemLookupResponse"]['Items']['Item']['ImageSets']['ImageSet']['MediumImage']
    self.large_image = attrs_h["ItemLookupResponse"]['Items']['Item']['ImageSets']['ImageSet']['LargeImage']
    
  end

  def parse_and_update_info(response)
    
    self.price = 
  end
end
